package shc.graduation.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import org.litepal.crud.DataSupport;

import java.util.List;

import shc.graduation.R;
import shc.graduation.bean.CodeGroup;
import shc.graduation.bean.PaoWangGroup;
import shc.graduation.bean.PaperGroup;

/**
 * Created by shuhuiChen on  2016/5/21  11:27.
 * Email ：shuhuiCSH@126.com
 */
public class GroupAdapter extends SimpleBaseAdapter<DataSupport> {

    private static int PROJECT_ID = 0;
    private static final int OPEN_CODE = 0;
    private static final int PAOWANG_ARTICLE = 1;
    private static final int PAPER_ARTICLE = 2;

    private static int Select_Index = -1;

    public GroupAdapter(Context context, List<DataSupport> data) {
        super(context, data);
    }

    public void setProject(int id) {
        PROJECT_ID = id;
    }

    public void setSelectIndex(int index) {
        Select_Index = index;
        notifyDataSetChanged();
    }

    @Override
    public int getItemResource() {
        return R.layout.item_listview_group;
    }

    @Override
    public View getItemView(int position, View convertView, SimpleBaseAdapter<DataSupport>.ViewHolder holder) {

        TextView nameTextView;

        nameTextView = holder.getView(R.id.item_group_name);

        if (position == Select_Index) {
            convertView.setBackgroundColor(context.getResources().getColor(R.color.light_gray));
            nameTextView.setTextColor(context.getResources().getColor(R.color.colorPrimary));
        } else {
            convertView.setBackgroundColor(context.getResources().getColor(R.color.transparent));
            nameTextView.setTextColor(context.getResources().getColor(R.color.item_text_blue));
        }

        switch (PROJECT_ID) {

            case OPEN_CODE:
                CodeGroup group = (CodeGroup) getItem(position);
                nameTextView.setText(group.getGroupName() + "");

                break;

            case PAOWANG_ARTICLE:
                PaoWangGroup paoWangGroup = (PaoWangGroup) getItem(position);
                nameTextView.setText(paoWangGroup.getGroupName() + "");

                break;

            case PAPER_ARTICLE:
                PaperGroup paperGroup = (PaperGroup) getItem(position);
                nameTextView.setText(paperGroup.getGroupName() + "");

                break;

            default:
                throw new IllegalStateException("error project state");
        }

        return convertView;
    }

    @Override
    public void removeAll() {
        Select_Index = -1;
        super.removeAll();
    }
}
